package cn.schoolwow.quickdao.test.module.business.user.log.flow;

import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickdao.domain.database.parent.UpgradeRequest;
import cn.schoolwow.quickdao.domain.entity.DatabaseUpgrade;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.instanceList.QueryInstanceList;
import org.junit.Assert;

import java.util.List;

public class CheckDatabaseUpgradeResultFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        DAO dao = flowContext.checkInstanceData(DAO.class);
        List<UpgradeRequest> upgradeRequestList = (List<UpgradeRequest>) flowContext.checkData("upgradeRequestList");

        List<String> commentList = QueryInstanceList.newQuery(upgradeRequestList)
                .execute()
                .getSingleFieldValueList("comment");

        long count = dao.query(DatabaseUpgrade.class)
                .addInQuery("comment", commentList)
                .execute()
                .count();
        Assert.assertEquals(upgradeRequestList.size(), count);
    }

    @Override
    public String name() {
        return "检查数据库升级语句结果";
    }
}
